package com.devops.admin.graphql;

import cn.hutool.core.bean.BeanUtil;
import com.aliyuncs.alidns.model.v20150109.*;
import com.devops.admin.model.DOSDomainRecord;
import com.devops.admin.model.Pagination;
import com.devops.admin.model.TableResult;
import com.devops.admin.service.AliyunReqResServer;
import com.devops.admin.vo.*;
import com.devops.common.annotation.DOSLog;
import com.devops.constant.DevOpsConstant;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsMutation;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @ClassName AliyunDnsDataFetcher
 * @Description TODO
 * @Author heyabo
 * @Date 2022/8/3 14:58
 * @Version 1.0
 **/
@DgsComponent
public class AliyunDnsDataFetcher {

    @Autowired
    AliyunReqResServer aliyunReqResServer;

    /**
     * 添加解析记录
     * @param request
     * @return
     */
    @DgsMutation
    @DOSLog(description = "添加解析记录")
    @RequiresPermissions(value = {DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR,DevOpsConstant.RoleCode.ADMINISTRATOR,
            DevOpsConstant.RoleCode.QA_ADMINISTRATOR},logical = Logical.OR)
    public AddDomainRecordResponse addDomainRecord(@InputArgument DOSDomainRecord request) {

        return aliyunReqResServer.addDomainRecord(request);
    }

    /**
     * 删除解析记录
     * @param requestVo
     * @return
     */
    @DgsMutation
    @DOSLog(description = "删除解析记录")
    @RequiresPermissions(value = {DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR,DevOpsConstant.RoleCode.ADMINISTRATOR,
            DevOpsConstant.RoleCode.QA_ADMINISTRATOR},logical = Logical.OR)
    public DeleteDomainRecordResponse deleteDomainRecord(@InputArgument("request") DeleteDomainRecordRequestVo requestVo) {

        return aliyunReqResServer.deleteDomainRecord(requestVo);

    }

    /**
     * 修改解析记录
     * @param request
     * @return
     */
    @DgsMutation
    @DOSLog(description = "修改解析记录")
    @RequiresPermissions(value = {DevOpsConstant.RoleCode.SUPER_ADMINISTRATOR,DevOpsConstant.RoleCode.ADMINISTRATOR,
            DevOpsConstant.RoleCode.QA_ADMINISTRATOR},logical = Logical.OR)
    public UpdateDomainRecordResponse updateDomainRecord(@InputArgument DOSDomainRecord request) {

        return aliyunReqResServer.updateDomainRecord(request);

    }

    /**
     * 查询所有域名列表
     * @param requestVo
     * @return
     */
    @DgsQuery
    @DOSLog(description = "查询所有域名列表")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public TableResult<DescribeDomainsResponse.Domain> getDomains(@InputArgument DescribeDomainsRequestVo requestVo, @InputArgument DOSPageVo pageVo) {

        return aliyunReqResServer.getDomains(requestVo,pageVo);

    }


    /**
     * 获取域名相关信息
     * @param requestVo
     * @return
     */
    @DgsQuery
    @DOSLog(description = "获取域名相关信息")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public DescribeDomainInfoResponse getDomainInfo(@InputArgument DescribeDomainInfoRequestVo requestVo) {

        return aliyunReqResServer.getDomainInfo(requestVo);
    }
    /**
     * 获取域名操作日志
     * @param requestVo
     * @return
     */
    @DgsQuery
    @DOSLog(description = "获取域名操作日志")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public TableResult<DescribeDomainLogsResponse.DomainLog> getDomainOperateLogs(@InputArgument DescribeDomainLogsRequestVo requestVo, DOSPageVo pageVo) {

        return aliyunReqResServer.getDomainOperateLogs(requestVo,pageVo);
    }

    /**
     * 查询域名所有记录
     * @param requestVo
     * @return
     */
    @DgsQuery
    @DOSLog(description = "查询域名所有记录")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public TableResult<DescribeDomainRecordsResponse.Record> getDomainRecords(@InputArgument("request") DOSDescribeDomainRecordsRequestVo requestVo,@InputArgument DOSPageVo pageVo) {

        return aliyunReqResServer.getDomainRecords(requestVo,pageVo);
    }

    /**
     * 查询记录相关信息
     * @param requestVo
     * @return
     */
    @DgsQuery
    @DOSLog(description = "查询记录相关信息")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public DescribeDomainRecordInfoResponse getDomainRecordInfo(@InputArgument("request") DescribeDomainRecordInfoRequestVo requestVo) {

        return aliyunReqResServer.getDomainRecordInfo(requestVo);
    }
}
